package com.linwen.javase.desgin_pattern.create.clone.copy;

/**
 * @ClassName TestCopy
 * @Description
 * @Author lin
 * @Date 2022/3/13 下午9:06
 * @Version V1.0
 */
public class TestCopy {
    public static void main(String[] args) {
        Company company = new Company();
        company.setName("大公司");
        company.setAddress("深圳市");
        company.setPhone("123456789");
        Staff staff = new Staff();
        staff.setName("张三");
        staff.setAge(18);
        staff.setGender("男");
        company.setStaff(staff);

        Company clone = company.clone();
        System.out.println("clone来的对象属性值完全一样");
        System.out.println(company);
        System.out.println(clone);

        System.out.println("如果重写了staff的clone（在company和staff中），则在修改staff时只影响clone对象");
        clone.getStaff().setName("李四");
        System.out.println(company);
        System.out.println(clone);
        System.out.println("使用序列话进行copy对象，对象都需要实现序列话接口");
        Company clone1 = CloneUtils.clone(company);
        clone1.getStaff().setName("王武");
        System.out.println(company);
        System.out.println(clone1);
    }
}
